package cz.acies.uniql.sql.element;

import org.dom4j.Element;
import org.dom4j.dom.DOMElement;


import cz.acies.uniql.dialect.Dialect;
import cz.acies.uniql.sql.UniQLExpr;

/**
 * The Class Alias.
 */
public class UniQLAlias extends UniQLExpr
{
	private static final long serialVersionUID = -2737595384675035231L;

	/**
	 * Konstruktor tridy alias.
	 */
	public UniQLAlias() {
	}

	/**
	 * Konstruktor tridy alias.
	 * 
	 * @param dialect - dialect
	 */
	public UniQLAlias(Dialect dialect) {
		super(dialect);
	}

	/**
	 * Konstruktor tridy alias.
	 * 
	 * @param dialect - dialect
	 * @param name - name
	 */
	public UniQLAlias(Dialect dialect, String name) {
		super(dialect, name);
	}

	/**
	 * Konstruktor tridy alias.
	 * 
	 * @param name - name
	 */
	public UniQLAlias(String name) {
		super(null, name);
	}
	
	// -----  -----------------------------------------------------------------

	/* (non-Javadoc)
	 * @see cz.acies.uniql.sql.UniQLExpr#translate()
	 */
	public String translate() throws Exception {
		String s = "";
		if (getName() != null && getName().length() > 0)s += getName();
		return s;
	}

	// -----  -----------------------------------------------------------------
	
	/* (non-Javadoc)
	 * @see cz.acies.uniql.sql.UniQLExpr#transToXML()
	 */
	public String transToXML() throws Exception {
		DOMElement node = new DOMElement("Alias");
		node.addAttribute("name", this.getName());
		return node.asXML();
	}
	
	/* (non-Javadoc)
	 * @see cz.acies.uniql.sql.UniQLExpr#transToXML(org.dom4j.dom.DOMElement)
	 */
	public DOMElement transToXML(DOMElement node) throws Exception {
		node.setName("UniQLAlias");
		return node;
	}
	
	/* (non-Javadoc)
	 * @see cz.acies.uniql.sql.UniQLExpr#xmlToExpr(java.lang.String)
	 */
	public UniQLExpr xmlToExpr(String xml) throws Exception {
		return this;
	}

	/* (non-Javadoc)
	 * @see cz.acies.uniql.sql.UniQLExpr#xmlToExpr(org.dom4j.Element)
	 */
	public UniQLExpr xmlToExpr(Element node) throws Exception {
		String s1 = node.attributeValue("name");
		if (s1 != null && s1.length() > 0) this.setName(s1);
		return this;
	}
	
	// -----  -----------------------------------------------------------------
	
	public String toString() {
		return "UniQLAlias ( "+this.getName()+" )";
	}
}
